<?php 
namespace mylogin;
use think\Db;
use think\Session;

// echo 111111111111;die;
//Step3：通过Authorization Code获取Access Token
include'./function.php';
$code = $_GET['code'];
// var_dump($code);die;

// $code = '8A9343B92DADAD78BA7AD94F3198E67A';
$token_url ='https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=101472874&client_secret=d62b7e79baf43ee60606c63e7170003b&code='.$code.'&redirect_uri=http://www.yunxiangyishang.xin/mylogin.php';
$token_res = https_request($token_url);
// $token_res ='access_token=62B9CA7A22C17F744927923D0B74E3B3&expires_in=7776000&refresh_token=EA4A9DDA37B8EA5E7034A7C98C874EDE';
$data = explode('&',$token_res);
$data = explode('=',$data[0]);
$token = $data[1];
// var_dump($token);die;
// Step4：使用Access Token来获取用户的OpenID
$openid_url = 'https://graph.qq.com/oauth2.0/me?access_token='.$token;
$open_res = https_request($openid_url);
$lpos = strpos($open_res, "(");
$rpos = strrpos($open_res, ")");
$open_res  = substr($open_res, $lpos + 1, $rpos - $lpos -1);
$msg = json_decode($open_res,true);
// var_dump($msg);die;
$openid = $msg['openid'];

// var_dump($openid);die;
// Step5：使用Access Token以及OpenID来访问和修改用户数据
$userinfo_url = 'https://graph.qq.com/user/get_user_info?access_token='.$token.'&oauth_consumer_key=101472874&openid='.$openid;
$userinfo =  https_request($userinfo_url);
$usermsg = json_decode($userinfo,true);

// var_dump($usermsg);die;
$nickname = $usermsg['nickname'];
$nickface = $usermsg['figureurl_2'];

session('webnickname',$nickname);
dump(session('webnickname'));die;



// session_start();
// $_SESSION['web']['nickname'] = $nickname;
// $_SESSION['web']['face'] = $nickface;

//print_r($_SESSION);die;
header("location:/");
// include'./index.php';



















 ?>





















